<template>
	<view style="margin-top: 170rpx;">
		<u-navbar :title="param.index==='3'?'我的发布':'我的喜欢'" @rightClick="rightClick" :autoBack="true">
		</u-navbar>

		<u-sticky offset-top="90" v-if="param.index==='3'">
			<view style="background-color: #ffffff;padding-top: 20rpx;" v-if="param.index==='3'">
				<view style="margin-left: 28rpx;margin-right: 28rpx;">
					<u-search :showAction="false" :animation="false" v-model="param.content"
						@search="getList()"></u-search>
				</view>
				<view style="display: flex;justify-content: center;">
					<u-tabs :list="list1" @click="click"></u-tabs>
				</view>
			</view>
		</u-sticky>
		<list :loveList="loveList" @child-event="getList()"  :type="params.type" :shiwuType="shiwuType" deleteButton="1" :shenType="param.index"></list>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import list from '../components/list.vue'
	export default {
		data() {
			return {

				timer: null,
				timer2: null,
				total: 0,
				index: '',
				loveList: [],
				list1: [{
					name: '已发布',
				}, {
					name: '审核中',
				}],
				param: {
					index: '',
					userId: '',
					content: '',
					pushAble: 0,
					pageSize: 6,
					pageNum: 1,
				}
			}
		},
		onUnload() {
			console.log(123)
			if (this.timer2) {
				clearTimeout(this.timer2); // 清除定时器  
			}
		},
		onPullDownRefresh() {
			uni.showLoading({
				title: '加载中'
			});
			this.param.pageNum = 1
			this.getList()
			this.timer = setTimeout(() => {
				uni.stopPullDownRefresh()
				uni.hideLoading();
			}, 1000)
		},
		onReachBottom() {
			this.getBottom()
		},
		methods: {
			async getBottom() {
				const that = this
				if (this.loveList.length < this.total) {
					this.param.pageNum++
					uni.showLoading({
						title: '加载中'
					});
					uni.request({
						url: that.$baseurl + "/font/getLikeOrPush",
						method: 'GET',
						data: that.param,
						success(res) {
							that.loveList = [...that.loveList, ...res.data.rows]
						}
					})
					uni.hideLoading();
				} else {
					this.$refs.uToast.show({
						type: 'default',
						title: '默认主题',
						message: "到底了...",
						iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/default.png'
					})
				}
			},
			async getList() {
				if (!this.$isLogin()) {
					return;
				}
				var user = uni.getStorageSync("loginUser")
				this.param.userId = user.id
				const res = await this.$myRuquest({
					url: '/font/getLikeOrPush',
					data: this.param
				})
				this.loveList = res.data.rows
				this.total = res.data.total
			},
			rightClick() {
				uni.navigateBack()
				console.log('rightClick');
			},
			leftClick() {
				uni.navigateBack()
				console.log('leftClick');
			},
			click(item) {
				this.param.pushAble = item.index
				console.log(item)
				this.getList()
			},
		},
		onLoad(options) {
			var index = options.index
			if (index !== null && index !== '' && index !== undefined) {
				this.param.index = index
			}
			this.getList()
		},
		components: {
			"list": list,
		}
	}
</script>

<style>

</style>